from django.db import models
from django.contrib import auth
from api.models import *
from django.db.models.signals import post_save

def create_profile(sender, **kw):
    user = kw["instance"]
    if kw["created"]:
        profile = UserProfile()
        profile.user = user
        profile.save()

post_save.connect(create_profile, sender=auth.models.User)

class UserProfile(models.Model):
    def __unicode__(self):
        return self.user.username

    user = models.OneToOneField(auth.models.User)
    friends = models.ManyToManyField('self',
            null = True,
            blank = True)
    shelf = models.ManyToManyField(Book,
            null = True,
            blank = True)

